package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.service.UserService;
import com.zzyl.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation(value = "用户分页",notes = "用户分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userDto",value = "用户DTO对象",required = true,dataType = "UserDto"),
            @ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
            @ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
    })
    public ResponseResult findByPage(@RequestBody UserDto userDto,
                                     @PathVariable("pageNum") int pageNum,
                                     @PathVariable("pageSize") int pageSize){

       PageResponse<UserVo> pageResponse = userService.findByPage(userDto,pageNum,pageSize);

       return  ResponseResult.success(pageResponse);

    }
    @PutMapping
    @ApiOperation(value = "新增用户",notes = "新增用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userDto",value = "用户DTO对象",required = true,dataType = "UserDto")
    })
    public ResponseResult addUser(@RequestBody UserDto userDto){

        Boolean  isSuccess = userService.addUser(userDto);

        return  ResponseResult.success(isSuccess);

    }

}
